<?php
/**
 * Die Klasse für einen Admin.
 *
 * @author Timo
 */
class Admin
{
    private $joomla_id             = 0;
    private $superAdmin            = false; // true -> darf alles
    private $administrated_leagues = array();
    private $administrated_series  = array();
    
    // Setzen des Super-Admin Status..
    public function SetSuperAdmin($sa)
    {
        if(is_bool($sa))
        {
            $this->superAdmin = $sa;
        }
        else
        {
            echo $sa . ' is not a boolean value.<br />';
        }
    }

    // Benutzer ist SuperAdmin?
    public function IsSuperAdmin()
    {
        return $this->superAdmin;
    }

    public function SetJID($id)
    {
        if(is_integer($id))
        {
            $this->joomla_id = $id;
        }
        else
        {
            echo $id . ' is not an integer.<br />';
        }
    }
    
    public function AdministrateLeague($league_id)
    {
        if(is_integer($league_id))
        {
            $this->administrated_leagues[] = $league_id;
        }
        else
        {
            echo $league_id . ' is not an integer.<br />';
            echo 'Function needs a league id.';
        }
    }
    
    public function RemoveFromLeague($league_id)
    {
      try
        {
          if(is_integer($league_id))
          {
            $i = 0;
            foreach($this->administrated_leagues as $league)
            {
                if($league->GetID() == $league_id)
                {
                    unset($this->administrated_leagues[$i]);
                    $this->administrated_leagues = array_values($this->administrated_leagues);
                    return true;
                }
                $i++;
            }
            echo 'A league with an ID of "' . $league_id . '" does not exist.';
            return false;
          }
          else
          {
              echo $league_id . ' is not an integer.';
              return false;
          }
        }
        catch (Exception $ex)
        {
          echo $ex;
          return false;
        }  
    }
    
    public function AdministrateSeries($series_id)
    {
        if(is_integer($series_id))
        {
            $this->administrated_series[] = $series_id;
        }
        else
        {
            echo $series_id . ' is not an integer.<br />';
            echo 'Function needs a series id.';
        }
    }
    
    public function RemoveFromSeries($series_id)
    {
        try
        {
          if(is_integer($series_id))
          {
            $i = 0;
            foreach($this->administrated_series as $series)
            {
                if($series->GetID() == $series_id)
                {
                    unset($this->administrated_series[$i]);
                    $this->administrated_series = array_values($this->administrated_series);
                    return true;
                }
                $i++;
            }
            echo 'A series with an ID of "' . $series_id . '" does not exist.';
            return false;
          }
          else
          {
              echo $series_id . ' is not an integer.';
              return false;
          }
        }
        catch (Exception $ex)
        {
          echo $ex;
          return false;
        }  
    }
   
    public function GetJID()
    {
        return $this->joomla_id;
    }
    
    public function GetAdministratedLeagues()
    {
        return $this->administrated_leagues;
    }
    
    public function GetAdministratedSeries()
    {
        return $this->administrated_series;
    }
}
?>